package com.bt.att;

import com.bt.att.dao.PhoneDao;
import com.bt.att.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * ChartDataReader.
 *
 * @author Zakir Magdum
 */
@Configurable
@Component
public class ChartDataReader {
    @Autowired
    private PhoneDao dao;

    public ChartData getChartData(ChartType type, String fromNumber, Date from, Date to) {
        List<ChartPoint> points = dao.getChartData(type, fromNumber, from, to);
        String seriesName = "Unknown";
        String axisTitle = "Unknown";
        switch (type) {
            case CallsByPerson:
                seriesName = "Number of Calls";
                axisTitle = "Number";
                break;
            case DurationByPerson:
                seriesName = "Duration of Calls";
                axisTitle = "Number";
                break;
            case TextsByPerson:
                seriesName = "Number of Messages";
                axisTitle = "Number";
                break;
            case CallsByTime:
                seriesName = "Number of Calls";
                axisTitle = "Hour";
                break;
            case DurationByTime:
                seriesName = "Duration of Calls";
                axisTitle = "Hour";
                break;
            case TextsByTime:
                seriesName = "Number of Messages";
                axisTitle = "Hour";
                break;
        }
        ChartSeries series = new ChartSeries(seriesName, points);
        ChartData chartData = new ChartData();
        chartData.addSeries(series);
        chartData.setTitle(type.toString());
        chartData.setAxisTitle(axisTitle);
        return chartData;
    }

    public ChartData getChartData(ChartType type, Phone phone, Date from, Date to) {
        return getChartData(type, phone.getNumber(), from, to);
    }
}
